<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var num=123.5769
        console.log(Math.ceil(num)); //向上取整
        console.log(Math.floor(num)); //向下取整
        console.log(Math.round(num));   //四舍五入取整
        console.log(Math.random()); //随机生成0-1之间的随机数

        //验证码示例：
        //定义一个数组，保存所有可见的字符
        function createCode(len){
            var arr=[0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K']
            var r=""
            for(var i=0; i<len; i++){
                //随机生成一个可以从数组中取到的下标值
                var index=Math.floor(Math.random()*arr.length);            
                r+=arr[index];
            }
            return r.toUpperCase();
        }
        //调用 -> 生成5位数验证码
        console.log(createCode(5));
        
    </script>
</body>
</html>